package com.hpin.mlxteacher.tree;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hpin.mlxteacher.R;
import com.hpin.mlxteacher.base.BaseActivity;
import com.hpin.mlxteacher.bean.People;
import com.hpin.mlxteacher.utils.LogUtil;

import java.util.List;

/**
 * 宝宝树 发布页面
 * Created by Aaron on 15/7/30.
 */
public class ReleaseActivity extends BaseActivity {

    private static final int CHOOSE_BABY_CODE = 10001;
    private static final int CHOOSE_LOCATION = 10002;
    private static final int CHOOSE_TITLE = 10003;
    private Intent mIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_release);

        initWidget();
    }

    private void initWidget() {

        TextView tv_left = (TextView) findViewById(R.id.tv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);

        tv_left.setText(getResources().getString(R.string.cancle));
        tv_title.setText(getResources().getString(R.string.baby_tree_release));
        tv_right.setText(getResources().getString(R.string.baby_tree_release));

        RelativeLayout rl_location = (RelativeLayout) findViewById(R.id.rl_location);
        RelativeLayout rl_babys = (RelativeLayout) findViewById(R.id.rl_babys);
        RelativeLayout rl_title = (RelativeLayout) findViewById(R.id.rl_title);


        tv_left.setOnClickListener(this);
        tv_right.setOnClickListener(this);

        rl_location.setOnClickListener(this);
        rl_babys.setOnClickListener(this);
        rl_title.setOnClickListener(this);
    }

    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.tv_left:

                finish();
                break;
            case R.id.tv_right://发布


                break;
            case R.id.rl_location://所在位置

                mIntent = new Intent(this, LocationActivity.class);
                startActivityForResult(mIntent, CHOOSE_LOCATION);

                break;
            case R.id.rl_babys://选择宝宝

                mIntent = new Intent(this, ChooseBabyActivity.class);
                startActivityForResult(mIntent, CHOOSE_BABY_CODE);

                break;
            case R.id.rl_title://选择标题

                mIntent = new Intent(this, ChooseTitleActivity.class);
                startActivityForResult(mIntent, CHOOSE_TITLE);

                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {

            case CHOOSE_BABY_CODE://选择宝宝
                if (data == null)
                    return;
                //获得到选中的接受人
                List<People> chooseedPeoples = (List<People>) data.getSerializableExtra("children");

                if (chooseedPeoples == null || chooseedPeoples.size() < 1)
                    return;

                for (People p : chooseedPeoples) {

                    String name = p.name;

                    LogUtil.e("TAG", "name==>" + name);
                }
                break;

             case CHOOSE_LOCATION://选择位置

                break;


        }

    }
}
